//
//  PepleTool.m
//  SwiftTest
//
//  Created by 李江湖 on 2018/7/16.
//  Copyright © 2018年 李江湖. All rights reserved.
//

#import "PepleTool.h"
#import "SwiftTest-Swift.h"

@implementation PepleTool
+(PepleTool *)shareManage{
    static PepleTool *seng = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        seng = [[PepleTool alloc]init];
    });
    return seng;
}
-(void)run{
    NSLog(@"%@在跑步",self.name);
    
}
-(void)eat{
    NSLog(@"%@在吃饭",self.name);
}
/**
 校验银行卡号是否有效
 */
- (BOOL) IsBankCard:(NSString *)cardNumber
{
    if(cardNumber.length == 0)
    {
        return NO;
    }
    NSString *digitsOnly = @"";
    char c;
    for (int i = 0; i < cardNumber.length; i++)
    {
        c = [cardNumber characterAtIndex:i];
        if (isdigit(c))
        {
            digitsOnly =[digitsOnly stringByAppendingFormat:@"%c",c];
        }
    }
    int sum = 0;
    int digit = 0;
    int addend = 0;
    BOOL timesTwo = false;
    for (NSInteger i = digitsOnly.length - 1; i >= 0; i--)
    {
        digit = [digitsOnly characterAtIndex:i] - '0';
        if (timesTwo)
        {
            addend = digit * 2;
            if (addend > 9) {
                addend -= 9;
            }
        }
        else {
            addend = digit;
        }
        sum += addend;
        timesTwo = !timesTwo;
    }
    int modulus = sum % 10;
    return modulus == 0;
}
@end
